<template>
    <div class="panel-body panel-info">
        <el-tabs v-model="activeName">
            <el-tab-pane name="first">
                <span slot="label"><i class="fa fa-cog"></i> 基础设置</span>
                <el-form v-if="formBase" :model="formBase" class="form" ref="formBase"  label-width="150px">
                    <div class="panel-main">
                        <el-form-item label="医生审核：" prop="verify_doctor">
                            <el-switch
                                v-model="formBase.verify_doctor"
                                active-text="开启"
                                inactive-text="关闭">
                            </el-switch>
                        </el-form-item>
                        <el-form-item label="商户审核：" prop="verify_shop">
                            <el-switch
                                v-model="formBase.verify_shop"
                                active-text="开启"
                                inactive-text="关闭">
                            </el-switch>
                        </el-form-item>
                    </div>
                    <el-form-item style="padding-left: 150px;margin-top: 50px">
                        <el-button type="primary" v-show="access(1301)" @click="update('base')">保 存</el-button>
                    </el-form-item>
                </el-form>
            </el-tab-pane>
            <el-tab-pane name="second">
                <span slot="label"><i class="fa fa-gift"></i> 积分设置</span>
                <el-form v-if="formIntegral" :model="formIntegral" class="form" ref="formIntegral" label-width="150px">
                    <div class="panel-main">
                        <el-form-item label="登录送积分：" prop="login">
                            <el-input size="medium" v-model="formIntegral.login" placeholder="登录赠送积分"></el-input>
                        </el-form-item>
                        <el-form-item label="注册送积分：" prop="register">
                            <el-input size="medium" v-model="formIntegral.register" placeholder="注册赠送积分"></el-input>
                        </el-form-item>
                    </div>
                    <el-form-item style="padding-left: 150px;margin-top: 50px">
                        <el-button type="primary" v-show="access(1301)" @click="update('integral')">保 存</el-button>
                    </el-form-item>
                </el-form>
            </el-tab-pane>
            <el-tab-pane name="third">
                <span slot="label"><i class="fa fa-user"></i> 用户设置</span>
                <el-form v-if="formIntegral" :model="formUser" class="form" ref="formUser" label-width="150px">
                    <div class="panel-main">
                        <el-form-item label="提现次数限制：" prop="cash_limit">
                            <el-input size="medium" v-model="formUser.cash_limit" placeholder="每月提现次数限制">
                                <template slot="append">次</template>
                            </el-input>
                        </el-form-item>
                        <el-form-item label="提现金额限制：" prop="cash">
                            <el-input size="medium" v-model="formUser.cash" placeholder="金额满多少才能提现">
                                <template slot="append">元</template>
                            </el-input>
                        </el-form-item>
                        <el-form-item label="一级代理抽成：" prop="agent_one">
                            <el-input size="medium" v-model="formUser.agent_one" placeholder="一级代理抽成百分比">
                                <template slot="append">%</template>
                            </el-input>
                        </el-form-item>
                        <el-form-item label="二级代理抽成：" prop="agent_two">
                            <el-input size="medium" v-model="formUser.agent_two" placeholder="二级代理抽成百分比">
                                <template slot="append">%</template>
                            </el-input>
                        </el-form-item>
                    </div>
                    <el-form-item style="padding-left: 150px;margin-top: 50px">
                        <el-button type="primary" v-show="access(1301)" @click="update('user')">保 存</el-button>
                    </el-form-item>
                </el-form>
            </el-tab-pane>
        </el-tabs>
    </div>
</template>
<!---->
<script>
import {ArticleCategoryUpdate, ConfigList, ConfigUpdate} from '@/utils/request';
    export default {
        data() {
            return {
                activeName: 'first',
                formBase: null,
                formIntegral: null,
                formUser: null,
            }
        },
        activated() {
            this.config();
        },
        methods: {
            //更新
            update(name){
                let formData;
                switch (name) {
                    case 'base':
                        formData = this.formBase;
                        break;
                    case 'integral':
                        formData = this.formIntegral;
                        break;
                    case 'user':
                        formData = this.formUser;
                        break;
                }
                ConfigUpdate(formData).then((res)=>{
                    if(res.code){
                        this.$notify.error({title: 'ERROR', message: res.msg});
                    }else{
                        this.$notify({
                            type: 'success',
                            duration:1000,
                            title: 'SUCCESS',
                            message: res.msg, onClose:()=>{}});
                    }
                });
            },
            config(){
                ConfigList({params: this.params}).then((res)=>{
                    if (res.code) {
                        this.$notify.error({title: 'ERROR', message: res.msg});
                    } else {
                        this.listData = res.data;
                        this.setting(this.listData);
                    }
                })
            },
            setting(data){
                this.formBase = {
                    type: 'base',
                    verify_doctor: Boolean(eval(data.base.verify_doctor.toLowerCase())),//医生是否需要审核
                    verify_shop: Boolean(eval(data.base.verify_shop.toLowerCase())),//商户是否需要审核
                };
                this.formIntegral = {
                    type: 'integral',
                    login: data.integral.login,//登录
                    register: data.integral.register,//注册
                };
                this.formUser = {
                    type: 'user',
                    cash_limit: data.user.cash_limit,//每月提现次数
                    cash: data.user.cash,//满多少才能提现
                    agent_one: data.user.agent_one,//一级代理抽成
                    agent_two: data.user.agent_two,//二级代理抽成
                };
            }
        }
    }
</script>
